<template>
  <div>
    <el-row :gutter="20" style="margin-bottom: 0px ">
      <el-col :span="6"> <el-card shadow="hover" class="grid-content grid-con-1">
          <div class="grid-num">{{ other.d1 }}</div>
          <div>总积分余额</div>
        </el-card> </el-col>
      <el-col :span="6"> <el-card shadow="hover" class="grid-content grid-con-1">
          <div class="grid-num">{{ other.d2 }}</div>
          <div>日派发积分</div>
        </el-card> </el-col>
      <el-col :span="6"> <el-card shadow="hover" class="grid-content grid-con-1">
          <div class="grid-num">{{ other.d3 }}</div>
          <div>月派发积分</div>
        </el-card> </el-col>
      <el-col :span="6"> <el-card shadow="hover" class="grid-content grid-con-1">
          <div class="grid-num">{{ other.d4 }}</div>
          <div>年派发积分</div>
        </el-card> </el-col>
    </el-row>
    <el-row :gutter="20" style="margin-bottom: 0px ">
      <el-col :span="6"> <el-card shadow="hover" class="grid-content grid-con-1">
          <div class="grid-num">{{ service.b1 }}</div>
          <div>总服务商</div>
        </el-card> </el-col>
      <el-col :span="6"> <el-card shadow="hover" class="grid-content grid-con-1">
          <div class="grid-num">{{ service.b2 }}</div>
          <div>本日新增服务商</div>
        </el-card> </el-col>
      <el-col :span="6"> <el-card shadow="hover" class="grid-content grid-con-1">
          <div class="grid-num">{{ service.b3 }}</div>
          <div>本周新增服务商</div>
        </el-card> </el-col>
      <el-col :span="6"> <el-card shadow="hover" class="grid-content grid-con-1">
          <div class="grid-num">{{ service.b4 }}</div>
          <div>本月新增服务商</div>
        </el-card> </el-col>
    </el-row>
    <el-row :gutter="20" style="margin-bottom: 0px ">
      <el-col :span="6"> <el-card shadow="hover" class="grid-content grid-con-1">
          <div class="grid-num">{{ subscriber.a1 }}</div>
          <div>总用户</div>
        </el-card> </el-col>
      <el-col :span="6"> <el-card shadow="hover" class="grid-content grid-con-1">
          <div class="grid-num">{{ subscriber.a2 }}</div>
          <div>本日新增用户</div>
        </el-card> </el-col>
      <el-col :span="6"> <el-card shadow="hover" class="grid-content grid-con-1">
          <div class="grid-num">{{ subscriber.a3 }}</div>
          <div>本周新增用户</div>
        </el-card> </el-col>
      <el-col :span="6"> <el-card shadow="hover" class="grid-content grid-con-1">
          <div class="grid-num">{{ subscriber.a4 }}</div>
          <div>本月新增用户</div>
        </el-card> </el-col>
    </el-row>
    <el-row :gutter="20" style="margin-bottom: 0px ">
      <el-col :span="6">
        <el-card shadow="hover" class="grid-content grid-con-1">
          <div class="grid-num">{{ order.c1 }}</div>
          <div>日生活商城订单</div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card shadow="hover" class="grid-content grid-con-1">
          <div class="grid-num">{{ order.c10 }}</div>
          <div>月服务商订单</div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card shadow="hover" class="grid-content grid-con-1">
          <div class="grid-num">{{ order.c2 }}</div>
          <div>周生活商城订单</div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card shadow="hover" class="grid-content grid-con-1">
          <div class="grid-num">{{ order.c3 }}</div>
          <div>月生活商城订单</div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card shadow="hover" class="grid-content grid-con-1">
          <div class="grid-num">{{ order.c4 }}</div>
          <div>年生活商城订单</div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card shadow="hover" class="grid-content grid-con-1">
          <div class="grid-num">{{ order.c5 }}</div>
          <div>日积分商城订单</div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card shadow="hover" class="grid-content grid-con-1">
          <div class="grid-num">{{ order.c6 }}</div>
          <div>周积分商城订单</div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card shadow="hover" class="grid-content grid-con-1">
          <div class="grid-num">{{ order.c7 }}</div>
          <div>月积分商城订单</div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card shadow="hover" class="grid-content grid-con-1">
          <div class="grid-num">{{ order.c8 }}</div>
          <div>日服务商订单</div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card shadow="hover" class="grid-content grid-con-1">
          <div class="grid-num">{{ order.c9 }}</div>
          <div>周服务商订单</div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card shadow="hover" class="grid-content grid-con-1" @click="navTo('zyMallOrder')">
          <div class="grid-num">{{ finance.e1 }}</div>
          <div>增加收入</div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card shadow="hover" class="grid-content grid-con-1" @click="navTo('zyMallOrder')">
          <div class="grid-num">{{ finance.e2 }}</div>
          <div>当日下单总金额</div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card shadow="hover" class="grid-content grid-con-1" @click="navTo('zyMallRefund')">
          <div class="grid-num">{{ finance.e3 }}</div>
          <div>当日退款订单</div>
        </el-card>
      </el-col>
    </el-row>
    <div shadow="hover" class="mgb20 userBox" style="height: 273px">
      <div class="user-info">
        <img :src="pic" class="user-avator" alt />
        <div class="user-info-cont">
          <div class="user-info-name">{{ name }}</div>
          <div>{{ role }}</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { api } from "@/api/index";
export default {
  name: "dashboard",
  setup() {
    const name = localStorage.getItem("ms_username");
    const role = name === "admin" ? "超级管理员" : "普通用户";
    return { name, role };
  },
  data() {
    return {
      name: localStorage.getItem("ms_username"),
      pic: this.$store.state.adminMsg.agentLogo,
      order: {},
      other: {},
      service: {},
      subscriber: {},
      finance: {}
    };
  },
  created() {
    this.getData()
  },
  methods: {
    navTo(item) {
      this.$router.push(item);
    },
    getData() {
      api('/web/home/order', {}).then((res) => { this.order = res.data; });
      api('/web/home/other', {}).then((res) => { this.other = res.data; });
      api('/web/home/service', {}).then((res) => { this.service = res.data; });
      api('/web/home/subscriber', {}).then((res) => { this.subscriber = res.data; });
      api('/web/home/finance', {}).then((res) => { this.finance = res.data; });

    },
  }
};
</script>

<style scoped lang="scss">
.el-row {
  margin-bottom: 20px;
}

::v-deep .el-col {
  margin-bottom: 10px;
}

.grid-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100px;
  align-items: center;
  justify-content: center;
  width: 100%;

  ::v-deep .el-card {
    width: 100%;

    .el-card__body {
      text-align: center;
    }
  }

  .grid-num {
    font-size: 30px;
    font-weight: bold;
  }
}

.grid-con-icon {
  font-size: 50px;
  width: 100px;
  height: 100px;
  text-align: center;
  line-height: 100px;
  color: #fff;
}

.grid-con-1 .grid-con-icon {
  background: rgb(45, 140, 240);
}

.grid-con-1 .grid-num {
  color: rgb(45, 140, 240);
}

.grid-con-2 .grid-con-icon {
  background: rgb(100, 213, 114);
}

.grid-con-2 .grid-num {
  color: rgb(45, 140, 240);
}

.grid-con-3 .grid-con-icon {
  background: rgb(242, 94, 67);
}

.grid-con-3 .grid-num {
  color: rgb(242, 94, 67);
}

.userBox {
  background-color: #fff;
  overflow: hidden;
  color: #303133;
  border-radius: 5px;
}

.user-info {
  padding-bottom: 20px;
  margin-bottom: 20px;
  text-align: center;
  position: relative;
  top: 50%;
  transform: translateY(-50%);
}

.user-avator {
  width: 120px;
  height: 120px;
  border-radius: 50%;
}

.user-info-cont {
  flex: 1;
  font-size: 14px;
  color: #999;
}

.user-info-cont div:first-child {
  font-size: 30px;
  color: #222;
}

.mgb20 {
  margin-bottom: 20px;
}

.todo-item {
  font-size: 14px;
}

.todo-item-del {
  text-decoration: line-through;
  color: #999;
}

.levelList {
  li {
    display: flex;
    justify-content: space-between;
    align-content: center;
    padding: 10px;

    :first-child {
      font-weight: 600;
    }

    :last-child {
      color: rgb(45, 140, 240);
      font-weight: 600;
      font-size: 19px;
    }
  }
}
</style>